package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
@Slf4j
public class PermissionController {


    @DubboReference
    PermissionService permissionService;

    /**
     * @Author: 涵哥 
     * @Date: 14:57 2021/1/19
     * @Parms [queryPageBean]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 对权限的动态维护-查询
    */
    @GetMapping("/findPage")
    public Result findPage(QueryPageBean queryPageBean){
        log.info("[权限数据-分页查询]queryPageBean: {}",queryPageBean);
        PageResult pageResult = permissionService.findPage(queryPageBean);

        return new Result(true,MessageConst.QUERY_PERMISSION_SUCCESS,pageResult);
    }

    /**
     * @Author: 涵哥
     * @Date: 16:14 2021/1/19
     * @Parms [permission]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 权限动态维护-新增
    */
    @PostMapping("/add")
    public Result add(@RequestBody Permission permission){
      log.info("[权限维护-新增]data: {}",permission);
      permissionService.add(permission);
      return new Result(true,MessageConst.ACTION_SUCCESS);
    }

    /**
     * @Author: 涵哥
     * @Date: 16:14 2021/1/19
     * @Parms [permission]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 权限动态维护-根据id删除
     */
    @PostMapping("/delete")
    public Result deleteById(Integer id){
        log.info("[权限动态维护-根据id删除]data : {}",id);
        permissionService.deleteById(id);
        return new Result(true,MessageConst.ACTION_SUCCESS);
    }


    /**
     * @Author: 涵哥
     * @Date: 16:14 2021/1/19
     * @Parms
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 权限动态维护-编辑
     */
    @PostMapping("/edit")
    public Result edid(@RequestBody Permission permission){
        log.info("[权限动态维护-编辑]data: {}",permission);
        permissionService.edit(permission);
        return new Result(true,MessageConst.ACTION_SUCCESS);
    }

    /**
     * @Author: 涵哥
     * @Date: 17:55 2021/1/19
     * @Parms [id]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 编辑的数据回显-据id查询
    */
    @GetMapping("/findById")
    public Result findById(Integer id){
        log.info("[编辑数据回显-据id返回]id :{}",id);
        Permission permission = permissionService.findById(id);
        return new Result(true,MessageConst.ACTION_SUCCESS,permission);
    }
}
